home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
Python 1.3.3
/
Python 133 68K
/
Lib
/
test
/
img
/
NOTYET
/
hexdump.py
next >
Wrap
Text File
|
1996-05-20
|
967b
|
57 lines
"""
Make a hex dump of a file
"""
import sys
sys.stdout = sys.stderr
import string
import macfs
def main():
# Ask for input if not specified in sys.argv[1:]
if not sys.argv[1:]:
srcfss, ok = macfs.PromptGetFile('Input file to dump:')
if not ok:
return
filename = srcfss.as_pathname()
process(filename)
else:
# Loop over all files to be processed
for filename in sys.argv[1:]:
process(filename)
sys.exit(1)
def process(filename):
print '------', filename
f = open(filename)
addr = -16
prevd = None
didskip = 0
while 1:
d = f.read(16)
if not d:
return
addr = addr + 16
if d == prevd:
if not didskip:
print '*'
didskip = 1
continue
outhex = ''
outstr = ''
for ch in d:
outhex = outhex + ('%02.2x '%ord(ch))
if ord(ch) < 32 or ord(ch) >= 0177:
outstr = outstr + '.'
else:
outstr = outstr + ch
print '%06.6x %-48.48s %s'%(addr, outhex, outstr)
if __name__ == '__main__':
main()